
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AdminLTE 2 | Discount</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" th:href="@{/adminlte/bower_components/bootstrap/dist/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/adminlte/bower_components/font-awesome/css/font-awesome.min.css}">
    <link rel="stylesheet" th:href="@{/adminlte/bower_components/Ionicons/css/ionicons.min.css}">
    <link rel="stylesheet" th:href="@{/adminlte/bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/adminlte/dist/css/AdminLTE.min.css}">
    <link rel="stylesheet" th:href="@{/adminlte/dist/css/skins/skin-blue.min.css}">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

    <!-- Main Header -->
    <div th:replace="@{/include/back_header}::header"></div>
    <!-- Left side column. contains the logo and sidebar -->
    <div th:replace="@{/include/back_sidebar}::sidebar"></div>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                基本信息表
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">折扣管理</a></li>
                <li class="active">基本信息</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <!-- /.box-header -->
                        <div class="box-body">
                            <table id="example" class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>折扣编号</th>
                                    <th>开始时间</th>
                                    <th>结束时间</th>
                                    <th>折扣种类</th>
                                    <th>折扣额度</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr th:each="discount:${discount}" >
                                        <td th:text="${discount.id}"></td>
                                        <td th:text="${discount.start}"></td>
                                        <td th:text="${discount.end}"></td>
                                        <td th:text="${discount.type}"></td>
                                        <td th:text="${discount.amount}"></td>
                                        <td class="col-operate">
                                            <button type="button" class="btn btn-modify btn-warning btn-sm"
                                                    data-toggle="modal"
                                                    data-target="#modal-default" onclick="modify(this)">修改
                                            </button>
                                            <button type="button" class="btn btn-delete btn-danger btn-sm">删除</button>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->
                    <!--modal-->
                    <div class="modal fade" id="modal-default">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span></button>
                                    <h4 class="modal-title">修改折扣信息</h4>
                                </div>
                                <form role="form" th:action="@{/discount/modify}" method="post">
                                    <div class="modal-body">
                                        <table style="width: 100%">
                                            <tbody>
                                            <tr>
                                                <td width="20%">折扣编号:</td>
                                                <td width="80%"><input type="text" readonly="readonly"
                                                                       class="form-control"
                                                                       name="id" id="id">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="20%">开始时间:</td>
                                                <td width="80%"><input type="text" class="form-control" name="start"
                                                                       id="name">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="20%">结束时间:</td>
                                                <td width="80%"><input type="text" class="form-control" name="end"
                                                                       id="gender">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="20%">折扣种类:</td>
                                                <td width="80%"><input type="text" class="form-control" name="type"
                                                                       id="age">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="20%">折扣额度:</td>
                                                <td width="80%"><input type="text" class="form-control" name="amount"
                                                                       id="academy">
                                                </td>
                                            </tr>

                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default pull-left" data-dismiss="modal">
                                            Close
                                        </button>
                                        <button type="submit" class="btn btn-primary">Save changes</button>
                                    </div>
                                </form>
                            </div>
                            <!-- /.modal-content -->
                        </div>
                        <!-- /.modal-dialog -->
                    </div>
                    <!-- /.modal -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <!-- Main Footer -->
    <div th:replace="@{/include/back_footer}::footer"></div>

</div>
<!-- ./wrapper -->

<!-- REQUIRED JS SCRIPTS -->

<script th:src="@{/adminlte/bower_components/jquery/dist/jquery.min.js}"></script>
<script th:src="@{/adminlte/bower_components/fastclick/lib/fastclick.js}"></script>
<script th:src="@{/adminlte/bower_components/bootstrap/dist/js/bootstrap.min.js}"></script>
<script th:src="@{/adminlte/dist/js/adminlte.min.js}"></script>
<script th:src="@{/adminlte/bower_components/datatables.net/js/jquery.dataTables.min.js}"></script>
<script th:src="@{/adminlte/bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js}"></script>
<script th:src="@{/adminlte/bower_components/jquery-slimscroll/jquery.slimscroll.min.js}"></script>
<script th:src="@{/adminlte/bower_components/layer-v3.1.1/layer/layer.js}"></script>
<script th:src="@{/adminlte/dist/js/demo.js}"></script>
<!-- page script -->
<script>
    $(function () {
        $("#discount").addClass("active");
        $(".btn-delete").on("click", function () {
            var table = $("#example").DataTable();
            var row=table.row($(this).parents('tr'))
            var tr=$(this).parents("tr");
            var idValue=tr.find("td:eq(0)").html();
            var currentName=tr.find("td:eq(1)").html();

            layer.confirm('确定删除【 ' + currentName + "】", {icon: 3, title: '提示'}, function (index) {
                $.ajax({
                    type: "POST",
                    url: "/discount/delete",
                    data: {id: idValue},
                    dataType:"json",
                    success: function (msg) {
                        if(msg["ok"]){
                            layer.msg("操作成功", {time: 700}, function () {
                              //  window.location.reload();
                                row.remove().draw();
                            });
                        }else {
                            layer.msg("删除失败");
                        }
                    }
                });
                layer.close(index);
            });


        });
        $('#example').DataTable({
            'paging': true,
            'lengthChange': true,
            'searching': true,
            'ordering': true,
            'bAutoWidth': false,
            'info': true,
            'autoWidth': false
        });
    })

    function modify(obj) {
        var tds = $(obj).parent().parent().find('td');
        $("#id").val(tds.eq(0).text());
        $("#name").val(tds.eq(1).text());
        $("#gender").val(tds.eq(2).text());
        $("#age").val(tds.eq(3).text());
        $("#academy").val(tds.eq(4).text());
        $("#major").val(tds.eq(5).text());
        $("#phone").val(tds.eq(6).text());
    }

    $(".sidebar-menu li").click(function (e) {
        $(".sidebar-menu li").removeClass("active");
        $(this).addClass("active");
    });
</script>
</body>

</html>